var e = require;
var t = module;
var o = exports;
var n = o;
Object.defineProperty(n, "__esModule", {value: !0});
var i = e("ADInterface"),
    a = (function () {
        function e() {
            (this._isLoadComplete = !1),
                (this._gameMusicVolume = -1),
                (this._gameEffectsVolume = -1),
                (this._onLoadCallbackRef = null),
                (this._onCloseCallbackRef = null),
                (this._onErrorCallbackRef = null),
                (this._errorReloadCount = 0),
                (this._lastCallShowTime = -1);
        }
        return (
            (e.prototype.init = function () {
                console.log("rewardedVideo init"),
                    (this._onLoadCallbackRef = this.onRewardedVideoLoad.bind(this)),
                    (this._onCloseCallbackRef = this.onRewardedVideoClose.bind(this)),
                    (this._onErrorCallbackRef = this.onRewardedVideoError.bind(this)),
                    this.createRewardedVideo();
            }),
            (e.prototype.showRewardedVideo = function (e) {
                console.log("showRewardedVideo");
                var t = new Date().getTime();
                (this._lastCallShowTime = t),
                    (this._stateCallback = e),
                    (this._gameMusicVolume = cc.audioEngine.getMusicVolume()),
                    (this._gameEffectsVolume = cc.audioEngine.getEffectsVolume());
            }),
            (e.prototype.destroyRewardedVideo = function () {
                console.log("destoryRewardedVideo"), (this._stateCallback = null), (this._isLoadComplete = !1);
            }),
            (e.prototype.onRewardedVideoShowSuccessHandler = function () {
                console.log("onRewardedVideoShowSuccess"),
                    this._stateCallback && this._stateCallback(i.VideoADState.RewardedVideoShow),
                    this.pause();
            }),
            (e.prototype.onRewardedVideoShowFailHandler = function (e) {
                console.log("onRewardedVideoShowFailHandler", e),
                    this._stateCallback && this._stateCallback(i.VideoADState.AdShowFail),
                    (this._stateCallback = null),
                    this.resume(),
                    this._errorReloadCount < 2 &&
                        (this.destroyRewardedVideo(), this.createRewardedVideo(), this._errorReloadCount++);
            }),
            (e.prototype.onRewardedVideoNotLoadHandler = function () {
                console.log("onRewardedVideoNotLoadHandler"),
                    this._stateCallback && this._stateCallback(i.VideoADState.AdNotLoaded),
                    (this._stateCallback = null),
                    this.destroyRewardedVideo(),
                    this.createRewardedVideo();
            }),
            (e.prototype.onRewardedVideoErrorHandler = function (e) {
                console.log("onRewardedVideoErrorHandler", e),
                    this._stateCallback && this._stateCallback(i.VideoADState.AdLoadFail),
                    (this._stateCallback = null),
                    this.resume(),
                    this._errorReloadCount < 2 &&
                        (this._errorReloadCount++,
                        console.log("重新加载激励视频"),
                        this.destroyRewardedVideo(),
                        this.createRewardedVideo());
            }),
            (e.prototype.onRewardedVideoCloseHandler = function (e) {
                console.log("onRewardedVideoCloseHandler", e),
                    (this._isLoadComplete = !1),
                    this.resume(),
                    e
                        ? this._stateCallback && this._stateCallback(i.VideoADState.RewardedVideoEnd)
                        : this._stateCallback && this._stateCallback(i.VideoADState.RewardedVideoClose),
                    (this._stateCallback = null);
            }),
            (e.prototype.pause = function () {
                cc.audioEngine.setMusicVolume(0), cc.audioEngine.setEffectsVolume(0), cc.game.pause();
            }),
            (e.prototype.resume = function () {
                cc.game.resume(),
                    -1 !== this._gameMusicVolume &&
                        (cc.audioEngine.setMusicVolume(this._gameMusicVolume), (this._gameMusicVolume = -1)),
                    -1 !== this._gameEffectsVolume &&
                        (cc.audioEngine.setEffectsVolume(this._gameEffectsVolume), (this._gameEffectsVolume = -1));
            }),
            e
        );
    })();
n.default = a;
